
import logging

from django.shortcuts import render
from rest_framework.views import APIView
from rest_framework.response import Response

from home.models import NavCategory
from home.serializers import NavCategorySerializer

logger = logging.getLogger('django')


# Create your views here.

# class HomeView(APIView):
#     def get(self, request):
#         logger.info('Hello World')
#         logger.error('Hello World')
#         logger.debug('Hello World')
#         return Response({'message': 'Hello World'})

class NavCateGoryAPIView(APIView):
    def get(self, request):
        """
        获取导航分类接口
        :param request:
        :return:
        """
        try:
            queryset = NavCategory.objects.filter(is_show=True, is_deleted=False)
            ser = NavCategorySerializer(queryset, many=True)
            logger.info(f"成功获取导航分类列表,共{len(ser.data)}条记录")
            return Response({
                "code": 1,
                "message": "SUCCESS",
                "data": ser.data
            })

        except Exception as e:
            logger.error(f"获取导航分类列表失败,失败原因:{e}")
            return Response({
                "code": 0,
                "message": str(e),
                "data": []
            })
